from cold_start_analyzer.base_analyzer import BaseAnalyzer
from cold_start_analyzer.consts import NOT_AVAILABLE
from cold_start_analyzer import db_helper
from cold_start_analyzer.log_helper import dlog

class Phase3ModuleInstantiate(BaseAnalyzer):
    description = "Ability启动: H:SourceTextModule::Instantiate"
    def get_result(self):
        """
        起点： app_thread
        H:SourceTextModule::Instantiate
        终点： app_thread
        H:SourceTextModule::Instantiate
        """
        if 'Phase2All' not in self.context:
            return NOT_AVAILABLE
        res = db_helper.get_function_cost(self.cursor, 'H:SourceTextModule::Instantiate',
                                           self.context['Phase2All']['end_ts']-1, None,
                                        thread_name=self.thread_name)
        if not res:
            dlog.error(f"query_function_cost failed: {self.thread_name}, res: {res}")
            return NOT_AVAILABLE
        return res[0][1] - res[0][0]
